package com.ruoyi.common.pay.alipay;

import com.egzosn.pay.ali.api.AliPayConfigStorage;
import com.egzosn.pay.ali.api.AliPayService;
import com.egzosn.pay.common.http.HttpConfigStorage;
import com.egzosn.pay.common.util.sign.SignUtils;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@Component
public class AliPayInitConFig {

    protected AliPayService service = null;
    @Resource
    private AutowireCapableBeanFactory spring;

    @PostConstruct
    public void init() {
        AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
        aliPayConfigStorage.setPid("2088831437181066");
        aliPayConfigStorage.setAppid("2021001163628765");
        aliPayConfigStorage.setKeyPublic("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApeNzRIfFxD16UXFeFvkCsMOTsdiOhPraDJsllIV+wRTQ5DTbRSVm/erdfOQ/CmloFY4oi4/ScM7NTc6DOe43SHJq3SHGrXpb9mudPRqUC6F2RMKMIFfmggItcgRrI0GZBT/ZBQWhulzZJKg6w5KVWN7tKV6QwxNVMS1rgrGbQnhB8lTgjQMcZYIvKDUagOZ1i1hX8h8vTDK4hOvuEpzZjdV2VZNZfKsf2GTdmMx0TSve/yYp+IQ+yStPUrnB7bk0P0IfJ8wxBVl3ugNT6uQdPSDPgDWnzt8FtVcbqItNc63BGdgB37tjdYRvr5E+cSydsuy0A96Y9XDfR6SAwnwZlQIDAQAB");
        aliPayConfigStorage.setKeyPrivate("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCl43NEh8XEPXpRcV4W+QKww5Ox2I6E+toMmyWUhX7BFNDkNNtFJWb96t185D8KaWgVjiiLj9Jwzs1NzoM57jdIcmrdIcatelv2a509GpQLoXZEwowgV+aCAi1yBGsjQZkFP9kFBaG6XNkkqDrDkpVY3u0pXpDDE1UxLWuCsZtCeEHyVOCNAxxlgi8oNRqA5nWLWFfyHy9MMriE6+4SnNmN1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RRqZ4d7CUosFJTvvN3I7EaIkhR+HvHCM60GoP2F8kIhvA0cH7QQNfs0Tvmvbx6ksFeVsSPEQTW4eVlgBonkJQDmklyVbl9yO06gaW5k1UII9OOkHwNGqcD4KBAoGBAK3qRDKKyotQthN/tHEHLUqhnvDv6LJ30Z1ZK8E23vfAxIDSzWyL7Af0TSOpEHkuIzUoiHfv+vPy165w0astror7fwnnEzyyO/MttK1Y0ozz+zSakFUy2EYRQWVgR46LMbiCbTJJM8SSPUpJLJOpKRbUXF9sLbvnEn64xYPP/k77");
      //  aliPayConfigStorage.setNotifyUrl(" http://eajtba.natappfree.cc/edh/payOrder");
        aliPayConfigStorage.setNotifyUrl(" http://easybuy.pfk2020.com:9092/edh/payOrder");
//        aliPayConfigStorage.setReturnUrl("http://a9wqab.natappfree.cc/edh/payOrder");
        aliPayConfigStorage.setSignType(SignUtils.RSA2.name());
        //aliPayConfigStorage.setSeller("2088831437181066");
        aliPayConfigStorage.setInputCharset("utf-8");
        //是否为测试账号，沙箱环境
        aliPayConfigStorage.setTest(false);

        //请求连接池配置
        HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
        //最大连接数
        httpConfigStorage.setMaxTotal(20);
        //默认的每个路由的最大连接数
        httpConfigStorage.setDefaultMaxPerRoute(10);
        service =  new AliPayService(aliPayConfigStorage, httpConfigStorage);
        //增加支付回调消息拦截器
        service.addPayMessageInterceptor(new AliPayMessageInterceptor());
        //设置回调消息处理
        service.setPayMessageHandler(spring.getBean(AliPayMessageHandler.class));
    }
}
